package com.example.mobile20306061480509homework;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMaintitle;
    private Button btnMaincar;
    private RadioButton radioyinqing;
    private RadioButton radioqianboli;
    private RadioButton radioluntai;
    private RadioButton radiodipan;
    private RadioButton radioqiangai;
    private RadioButton radioxuangua;
    private RadioButton radiozuoyi;
    private RadioButton radiofangxiangpan;
    private RadioButton radiochejia;
    private RadioButton radiochemen;
    private RadioButton radiohouboli;
    private RadioGroup Radgro;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btnMaincar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int radgro=Radgro.getCheckedRadioButtonId();
                if (radgro!=-1){
                    RadioButton radioButton=findViewById(radgro);
                    Intent intent=new Intent();
                   intent.putExtra("Main2",radioButton.getText().toString());
                   setResult(RESULT_OK,intent);
                   finish();
                }else{
                    new AlertDialog.Builder(MainActivity.this)
                            .setMessage("请选择原材料")
                            .setPositiveButton("确定",null)
                            .create()
                            .show();
                }
            }
        });

    }

    private void initView() {
        tvMaintitle = (TextView) findViewById(R.id.tvMaintitle);
        btnMaincar = (Button) findViewById(R.id.btnMaincar);
        radioyinqing = (RadioButton) findViewById(R.id.radioyinqing);
        radioqianboli = (RadioButton) findViewById(R.id.radioqianboli);
        radioluntai = (RadioButton) findViewById(R.id.radioluntai);
        radiodipan = (RadioButton) findViewById(R.id.radiodipan);
        radioqiangai = (RadioButton) findViewById(R.id.radioqiangai);
        radioxuangua = (RadioButton) findViewById(R.id.radioxuangua);
        radiozuoyi = (RadioButton) findViewById(R.id.radiozuoyi);
        radiofangxiangpan = (RadioButton) findViewById(R.id.radiofangxiangpan);
        radiochejia = (RadioButton) findViewById(R.id.radiochejia);
        radiochemen = (RadioButton) findViewById(R.id.radiochemen);
        radiohouboli = (RadioButton) findViewById(R.id.radiohouboli);
        Radgro = (RadioGroup) findViewById(R.id.Radgro);
    }
}